package com.demo.fullink.rabbitmq;

import com.alibaba.fastjson.JSON;
import com.demo.fullink.config.RabbitConfig;
import com.demo.fulllink.module.po.OrderPO;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class MQProducer {
    @Autowired
    private RabbitTemplate rabbitTemplate;
    
    /**
     * 发送通知MQ
     *
     * @param orderPO
     */
    public void sendNotify(OrderPO orderPO) {
        String notifyMessage = JSON.toJSONString(orderPO);
        rabbitTemplate.convertAndSend(RabbitConfig.ORDER_NOTIFY_QUEUE_EXCHANGE, RabbitConfig.ORDER_NOTIFY_KEY, notifyMessage);
    }
    
    /**
     * 发送订单MQ
     *
     * @param orderPO
     */
    public void sendOrder(OrderPO orderPO) {
        String orderMessage = JSON.toJSONString(orderPO);
        rabbitTemplate.convertAndSend(RabbitConfig.PLACE_ORDER_QUEUE_EXCHANGE, RabbitConfig.PLACE_ORDER_KEY, orderMessage);
    }
}
